import store from '../index'
import axios from '@/z/zfunction/$axios'
const state = {
  StationPiddata: {},
  ChargeCarSearchPcs: {},
  Station: [],
}
const getters = {}
const mutations = {
  SETStationPiddata(state, [pid, StationPid]) {
    state.StationPiddata[pid] = StationPid
  },
  setStation(state, datas) {
    state.Station = datas
  },
  SETChargeCarSearchPcs(state, [pid, ChargeCarSearchPcsdata]) {
    state.ChargeCarSearchPcs[pid] = ChargeCarSearchPcsdata
  },
}
const actions = {
  async getStationPidfn({ commit, state }, pid = 'USearch') {
    if (state.StationPiddata[pid]) {
      return state.StationPiddata[pid]
    } else {
      let url = '/StationPid',
        updata = { pid: pid }
      if (pid == 'USearch') {
        url = '/Station'
        updata = { id: store.state.user.USearch.pcs }
      }
      let pardata = await axios.post(url, updata)
      let { data } = pardata
      commit('SETStationPiddata', [pid, data])
      return data
    }
  },
  async getChargeCarSearchPcsfn({ commit, state }, pid = 'USearch') {
    if (pid == 'USearch') {
      return []
    }
    if (state.ChargeCarSearchPcs[pid]) {
      return state.ChargeCarSearchPcs[pid]
    } else {
      let url = '/ChargeCarSearchPcs',
        updata = { sum: 1, pcs1: pid }
      // let url="/ChargeCarPcs",updata={pcs:pid};
      let pardata = await axios.post(url, updata)
      let { data } = pardata
      commit('SETChargeCarSearchPcs', [pid, data])

      return data
    }
  },
}

export default { state, getters, mutations, actions }
